﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
    public class Ctbl_CatTags:IData<tbl_CatTags>
    {

        public Ctbl_CatTags(String myconnecString) : base(myconnecString) { 

        }
        protected override int InsertOnSubmit(tbl_CatTags item, int t)
        {
            return connec.ExecuteNonQuery("proCatTags", CommandType.StoredProcedure, new SqlParameter("@flag", t),
                new SqlParameter("@" + tbl_CatTags.c_IdCat, item.IdCat), new SqlParameter("@" + tbl_CatTags.c_CatName, item.CatName),
                new SqlParameter("@" + tbl_CatTags.c_IdMenu, item.IdMenu));
        }

        public override List<tbl_CatTags> GetAll(tbl_CatTags item)
        {
            return GetAll().FindAll(p=>p.IdCat==item.IdCat && p.CatName==item.CatName && p.IdMenu==item.IdMenu);
        }

        public override tbl_CatTags GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p => p.IdCat == Convert.ToInt32(id));
        }

        public override tbl_CatTags GetItem(System.Data.IDataReader dr)
        {
            tbl_CatTags obj = new tbl_CatTags();
            obj.IdCat = Convert.ToInt32(dr[tbl_CatTags.c_IdCat]);
            obj.IdMenu = Convert.ToInt32(dr[tbl_CatTags.c_IdMenu]);
            obj.CatName = dr[tbl_CatTags.c_CatName].ToString();
            obj.Menu = dr[tbl_CatTags.c_Menu].ToString();
            //Menu
            return obj;
        }

        public override List<tbl_CatTags> GetAll()
        {
            return GetAll(this.strSelect+tbl_CatTags.b_tbl_CatTags,CommandType.Text);
        }
    }
}
